package com.n.application;

import javax.servlet.ServletContextEvent;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.n.dao.CodeValueDao;
import com.n.dao.CustomerDao;
import com.n.dao.SupplierDao;

public class SystemContextLoaderListener extends ContextLoaderListener{
	
	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		
		ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());  
		CodeValueDao codeValueDao = (CodeValueDao)applicationContext.getBean("codeValueDao");
		CustomerDao customerDao = (CustomerDao)applicationContext.getBean("customerDao");
		SupplierDao supplierDao = (SupplierDao)applicationContext.getBean("supplierDao");

		System.out.println("========= 初始化缓存 =====================");
		SystemCache.buildCodeValue(codeValueDao);
		SystemCache.buildCustomer(customerDao);
		SystemCache.buildSupplier(supplierDao);
		System.out.println("=========================================");
		
	}
	
}
